package com.sayimo.maker.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sayimo.framework.exception.DaoException;
import com.sayimo.framework.exception.ServiceException;
import com.sayimo.maker.base.dao.AdpositionInterfaceDao;
import com.sayimo.maker.base.service.AdpositionInterfaceService;
import com.sayimo.maker.base.vo.Adposition;
import com.sayimo.maker.commons.Constant;



/**
 * @Copyright (c) 2015 广东省尚一互联网有限公司
 * @Project: schoolmallapi
 * @ClassName: AdpositionInterfaceServiceImpl
 * @Description: 广告
 * @author:	chenjia
 * @date:	日期：2016年2月27日  时间：上午11:35:18
 * @version 1.0.0
 */
@Service(value="adpositionInterfaceServiceImpl")
public class AdpositionInterfaceServiceImpl implements AdpositionInterfaceService{
	private static Log logger = LogFactory.getLog(AdpositionInterfaceServiceImpl.class);
	
	
	@Autowired
	private AdpositionInterfaceDao adpositionInterfaceDao;
	
	public AdpositionInterfaceDao getAdpositionInterfaceDao() {
		return adpositionInterfaceDao;
	}

	public void setAdpositionInterfaceDao(
			AdpositionInterfaceDao adpositionInterfaceDao) {
		this.adpositionInterfaceDao = adpositionInterfaceDao;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public Map<String,Object> getAdpositionListByTag(String tag) throws ServiceException {
		Map<String,Object> map=new HashMap<String,Object>();
		try{
			List<Adposition> list=adpositionInterfaceDao.getAdpositionListByTag(tag);
			if(list!=null&&list.size()>=0){
				for(Adposition ad:list){
					Map<String,Object> tempMap=new HashMap<String,Object>();
					if(tempMap.get("id")==null){
						tempMap.put("id", "");
					}else{
						tempMap.put("id", ad.getId());
					}
					if(tempMap.get("adName")==null){
						tempMap.put("adName", "");
					}else{
						tempMap.put("adName", ad.getAdName());
					}
					if(tempMap.get("adLink")==null){
						tempMap.put("adLink", "");
					}else{
						tempMap.put("adLink", ad.getAdLink());
					}
					if(tempMap.get("sort")==null){
						tempMap.put("sort", "");
					}else{
						tempMap.put("sort", ad.getSort());
					}
					if(tempMap.get("details")==null){
						tempMap.put("details", "");
					}else{
						tempMap.put("details", ad.getDetails());
					}
					if(tempMap.get("photoUrl")==null){
						tempMap.put("photoUrl", "");
					}else{
						tempMap.put("photoUrl", ad.getPhotoUrl());
					}
					if(tempMap.get("status")==null){
						tempMap.put("status", "");
					}else{
						tempMap.put("status", ad.getStatus());
					}
				}
				Map resultMap=new HashMap();
				resultMap.put("adpositionList", list);
				map.put(Constant.STATUS, Constant.STATUS_SUCCESS);
				map.put(Constant.DATA, resultMap);
				return map;
			}else{
				map.put(Constant.STATUS, Constant.STATUS_ERROR);
				map.put(Constant.ERROR_CODE, Constant.SELECT_ERROR);
				return map;
			}
		}catch(DaoException de){
			logger.error(de);
			throw new ServiceException(de);
		}
		
	}
}
